package com.dragon.sdgp.common.exception;

import com.auth0.jwt.exceptions.*;
import com.dragon.sdgp.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.xml.bind.ValidationException;


@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ValidationException.class)
    public R handlerValidationException(ValidationException e) {
        return R.fail(410, e.getMessage());
    }

    @ExceptionHandler(UserCountLockException.class)
    public R handlerUserCountLockException(UserCountLockException e) {
        return R.fail(409, e.getMessage());
    }

    @ExceptionHandler({TokenExpiredException.class, SignatureVerificationException.class, AlgorithmMismatchException.class, InvalidClaimException.class})
    public void handlerJWTVerificationException(JWTVerificationException e){
        log.info(e.getMessage());
    }

    @ExceptionHandler(DataTypeException.class)
    public R handlerRegExpException(DataTypeException e) {
        return R.fail(411, e.getMessage());
    }
}
    
 

